package cn.lyn4ever.goods.web.controller;

import cn.lyn4ever.common.R;
import cn.lyn4ever.entity.GoodsSku;
import cn.lyn4ever.goods.web.service.GoodsSkuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 商品的sku表，每一个商品对应多个sku表(GoodsSku)表控制层
 *
 * @author makejava
 * @since 2020-03-26 22:55:31
 */
@RestController
@RequestMapping("goodsSku")
@Api( description = "商品SKU接口详情")
public class GoodsSkuController {
    /**
     * 服务对象
     */
    @Resource
    private GoodsSkuService goodsSkuService;


    @GetMapping("getlistBySpuid/{spuid}")
    public R getlistBySpuid(@PathVariable("spuid") Integer spuid){
        List<GoodsSku> list = goodsSkuService.getGoodsSkuBySpuId(spuid);
         if(!list.isEmpty()){
             return R.ok().put("data", list);
         }

        return R.error("没有sku");
    }

    @ApiOperation("获取单个sku详情，带spu信息")
    @GetMapping("getOne/{skuid}")
    public R getOne(@PathVariable("skuid") Integer skuid){
        Map map  = goodsSkuService.getOne(skuid);
        if(!map.isEmpty()){
            return R.ok().put("data", map);
        }

        return R.error("没有sku");
    }

}